#include<bits/stdc++.h>
#define rg register
#define file(x)freopen(x".in","r",stdin);freopen(x".out","w",stdout)

using namespace std;

const int maxn=1e6+10;

int n;
int Sa[maxn],Rk[maxn];
int Len[maxn<<1];

inline bool check1()
{
	static bool vis[maxn];
	for(rg int i=1;i<=n;i+=1)vis[i]=false;
	for(rg int i=1;i<=n;i+=1)vis[Sa[i]]=true;
	for(rg int i=1;i<=n;i+=1)
		if(vis[i]==false)return false;
	for(rg int i=1;i<=n;i+=1)Rk[Sa[i]]=i;
	return true;
}
namespace BCJ{
	int Fa[maxn],Size[maxn],Max[maxn],Min[maxn];
	inline void init()
	{
		for(rg int i=1;i<=n;i+=1)Size[Fa[i]=i]=1,Max[i]=Min[i]=Rk[i];
	}
	inline int find(int x)
	{
		return Fa[x]==x?x:Fa[x]=find(Fa[x]);
	}
	inline void merge(int x,int y)
	{
		x=find(x),y=find(y);
		if(x==y)return;
		if(Size[x]<Size[y])swap(x,y);
		Fa[y]=x,Size[x]+=Size[y];
		Max[x]=max(Max[x],Max[y]);
		Min[x]=min(Min[x],Min[y]);
	}
}
int cnt[maxn],belong[maxn],tnt;
bool Mark[maxn];int pre[maxn];
inline void solve()
{
	scanf("%d",&n);
	for(rg int i=1;i<=n;i+=1)scanf("%d",Sa+i),Sa[i]+=1;
	for(rg int i=1;i<(n<<1);i+=1)scanf("%d",Len+i);
	for(rg int i=1;i<(n<<1);i+=2)
		if(!(Len[i]&1))
		{
			puts("-1");
			return;
		}
		else (++Len[i])>>=1;
	for(rg int i=2;i<(n<<1);i+=2)
		if(Len[i]&1)
		{
			puts("-1");
			return;
		}
		else Len[i]>>=1;
	if(!check1())
	{
		puts("-1");
		return;
	}
	for(rg int i=1,x=1;i<(n<<1);i+=2,x+=1)
		if(Len[i]>min(x,n-x+1)||Len[i]==0)
		{
			puts("-1");
			return;
		}
	for(rg int i=2,x=1;i<(n<<1);i+=2,x+=1)
		if(Len[i]>min(x,n-x))
		{
//			cerr<<"!!!"<<i<<" "<<x<<" "<<Len[i]<<endl;
			puts("-1");
			return;
		}
	Rk[n+1]=0;
	BCJ::init();
	auto id1=[&](int x){return (x-1)<<1|1;};
	auto id2=[&](int x){return x<<1;};
	for(rg int i=1,p=0,maxr=0;i<=n;i+=1)
	{
		int ago=1;
		if(maxr>=i)
		{
			int lst=(p<<1)-i;
			ago=min(maxr-i+1,Len[id1(lst)]);
		}
		if(ago>Len[id1(i)])
		{
			puts("-1");
			return;
		}
		while(ago<Len[id1(i)])
		{
			BCJ::merge(i-ago,i+ago);
			ago+=1;
		}
		if(i+ago-1>maxr)maxr=i+ago-1,p=i;
	}
	for(rg int i=1,p=0,maxr=0;i<n;i+=1)
	{
		int ago=0;
		if(maxr>i)
		{
			int lst=(p<<1)-i;
			ago=min(maxr-i,Len[id2(lst)]);
		}
		if(ago>Len[id2(i)])
		{
			puts("-1");
			return;
		}
		while(ago<Len[id2(i)])
		{
			BCJ::merge(i-ago,i+ago+1);
			ago+=1;
		}
		if(i+ago>maxr)maxr=i+ago,p=i;
	}
	for(rg int i=0;i<=n;i+=1)cnt[i]=0;
	for(rg int i=1;i<=n;i+=1)
		if(BCJ::find(i)==i)
		{
			cnt[BCJ::Min[i]]+=1;
			cnt[BCJ::Max[i]]-=1;
		}
	for(rg int i=1;i<n;i+=1)cnt[i]+=cnt[i-1];
	tnt=0;
	for(rg int i=1;i<=n;i+=1)
	{
		rg int j=i;
		while(j<n&&cnt[j])j+=1;
		++tnt;
		for(rg int k=i;k<=j;k+=1)belong[k]=tnt;
		i=j;
	}
	for(rg int i=1;i<n;i+=1)Mark[i]=false;
	for(rg int i=0;i<=n;i+=1)pre[i]=0;
	for(rg int i=1;i<n;i+=1)
	{
		int x=Sa[i],y=Sa[i+1];
		if(Rk[x+1]<Rk[y+1])continue;
		Mark[i]=true;
	}
	for(rg int i=1;i<=n;i+=1)pre[i]=pre[i-1]+Mark[i-1];
	vector<pair<int,int> >Seg;
	auto diff=[&](int x,int y)
			  {
//				  cerr<<"!!!"<<x<<" "<<y<<endl;
				  x=Rk[x],y=Rk[y];
				  if(x>y)swap(x,y);
				  if(belong[x]==belong[y])return true;
				  if(pre[x]!=pre[y])return false;
				  Seg.emplace_back(belong[x],belong[y]);
				  return false;
			  };
	for(rg int i=1,x=1;i<(n<<1);i+=2,x+=1)
		if(Len[i]<min(x,n-x+1)&&diff(x-Len[i],x+Len[i]))
		{
			puts("-1");
			return;
		}
//	cerr<<"____________"<<endl;
	for(rg int i=2,x=1;i<(n<<1);i+=2,x+=1)
		if(Len[i]<min(x,n-x)&&diff(x-Len[i],x+Len[i]+1))
		{
			puts("-1");
			return;
		}
	static int End[maxn];
	for(rg int i=1;i<=n;i+=1)End[belong[i]]=i;
	static int Min[maxn];
	for(rg int i=1;i<=tnt;i+=1)Min[i]=tnt+1;
	for(auto [l,r]:Seg)Min[l]=min(Min[l],r);
	int R=n+1;
	for(rg int i=1;i<=tnt;i+=1)
	{
		if(R==i)
		{
			Mark[End[i-1]]=true;
			R=n+1;
		}
		R=min(R,Min[i]);
	}
	int count=0;
	static int Ans[maxn];
	Ans[0]=0;for(rg int i=1;i<=n;i+=1)Ans[Sa[i]]=Ans[Sa[i-1]]+Mark[i-1];
	for(rg int i=1;i<=n;i+=1)
		if(Ans[i]>26)
		{
			puts("-1");
			return;
		}
	for(rg int i=1;i<=n;i+=1)putchar('a'+Ans[i]);puts("");
}

int main()
{
	file("string");
	int T;scanf("%d",&T);
	while(T--)solve();
	return 0;
}
/*
  3
8
4 6 5 3 2 0 1 7
1 0 3 0 1 0 1 0 1 0 1 0 1 0 1
8
2 5 7 0 4 3 6 1
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
8
2 1 5 4 0 3 6 7
2 1 6 8 7 3 13 13 6 3 22 17 14 14 10
 */
